//
//  LYCHeaderView.m
//  爱鲜蜂
//
//  Created by 廖易诚 on 16/6/17.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "LYCHeaderView.h"
#import "SDCycleScrollView.h"
#import "ActivityButton.h"
#import "LYCHomeModel.h"

#define margin 30

@interface LYCHeaderView ()<SDCycleScrollViewDelegate>

@property (nonatomic, weak) SDCycleScrollView *scrollView;

@property (nonatomic, weak) UIView *bottomView;

@property (nonatomic, strong) NSMutableArray *buttons;
@end

@implementation LYCHeaderView




- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
//        // 添加展示图片轮播器的view

        SDCycleScrollView *scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height - 80) delegate:self placeholderImage:[UIImage imageNamed:@"icon_icons_holder"]];
        scrollView.autoScroll = YES;
        scrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        scrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        [self addSubview:scrollView];
        self.scrollView = scrollView;
        
        UIView *bottomView = [[UIView alloc] init];
        [self addSubview:bottomView];
        self.bottomView = bottomView;
        bottomView.hm_x = 0;
        bottomView.hm_y = scrollView.hm_height;
        bottomView.hm_width = self.hm_width;
        bottomView.hm_height = self.hm_height - scrollView.hm_height;
        
        
        for (int i = 0; i < 4; i ++) {
            ActivityButton *button = [[ActivityButton alloc] init];
            [bottomView addSubview:button];
            [self.buttons addObject:button];
            
            
            
        }
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    int i = 0;
    for (ActivityButton *button in self.buttons) {
        
        button.hm_width = ([UIScreen hm_screenWidth] - 5*margin)/4;
        button.hm_height = self.bottomView.hm_height;
        button.hm_x = margin + (button.hm_width + margin) * i;
        NSLog(@"w = %f,x = %f",button.hm_width,button.hm_x);
        button.hm_y = 0;
        i++;
    }
}

- (void)setImageGroups:(NSArray *)imageGroups {
    _imageGroups = imageGroups;
    self.scrollView.imageURLStringsGroup = imageGroups;
}

- (NSMutableArray *)buttons {
    if (!_buttons) {
        _buttons = [NSMutableArray array];
    }
    return _buttons;
}

- (void)setIcons:(NSArray *)icons {
    _icons = icons;

    int i = 0;
    for (ActivityButton *button in self.buttons) {
        LYCHomeModel *model = icons[i];
        [button.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
        //        [button setImage:icon forState:UIControlStateNormal];
        switch (i) {
            case 0:{
                button.textLabel.text = @"抽奖";
            }
                break;
            case 1:{
                button.textLabel.text = @"秒杀";
            }
                break;
            case 2:{
                button.textLabel.text = @"抢红包";
            }
                break;
            case 3:{
                button.textLabel.text = @"蜂抱团";
            }
                break;
                
            default:
                break;
        }
        i++;
    }
}

@end
